home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10232 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: castle.nando.net!news
  2. From: actuary@nando.net   (Bill McCarthy)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Another a.s.a.p. to do with structures and pointers and arrays
  5. Date: 16 Mar 1996 03:24:58 GMT
  6. Organization: Nando.net Public Access
  7. Message-ID: <4idcaa$741@castle.nando.net>
  8. References: <4ic8vq$fpn@badger.wmin.ac.uk>
  9. Reply-To: actuary@nando.net (Bill McCarthy)
  10. NNTP-Posting-Host: grail2615.nando.net
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4ic8vq$fpn@badger.wmin.ac.uk>,
  14. Idoia Lertxundi <gsoec@wmin.ac.uk> writes:
  15.  
  16. >I have a struct:
  17. >
  18. >typedef struct read_file_module_tag
  19. >{
  20. >char code[LENGTHCODE];
  21. >char module_name[LENGTHMODULE_NAME];
  22. >char description[LENGTHDESCRIPTION];
  23. >char module_leader[LENGTHLEADER];
  24. >char result[LENGTHRESULT];
  25. >char corecoursecodes[LENGTHCOURSECODES];
  26. >char optionalcoursecodes[LENGTHCOURSECODES];
  27. >char andprereqcodes[LENGTHREQUISITES];
  28. >char orprereqcodes[LENGTHREQUISITES];
  29. >char andcoreqcodes[LENGTHREQUISITES];
  30. >char orcoreqcodes[LENGTHREQUISITES];
  31. >struct read_file_module_tag *nextfm;
  32. >}FILEMODULE;
  33. >
  34. >look at the char courecoursecodes[XXX] O.K.?
  35. >
  36. >then reading a name1,name2,name3 list with strtok fuction
  37. >I have stored them in a 
  38. >
  39. >    char *ccoursecodes[10];
  40. >
  41. >then when I try do this copy:
  42. >
  43. >    strcpy(mlst->corecoursecodes[i],ccoursecodes[i]);
  44. >the thing goes wrong no casting for argumenet 1.
  45.  
  46. Well ya, the first argument is suppose to be a char *.  Instead
  47. you are given strcpy a char.  Copy a string into a char???  Also,
  48. you will need to define mist as a pointer to type FILEMODULE
  49. and, of course, allocate space for a structure of that type.
  50.  
  51. >and if I change the above structure char type to char *...[]
  52. >does compile but it gives a segmentation fault when running.
  53. >Help!! S.O.S.
  54.  
  55. Now you're getting warmer.  The segmentation fault probably
  56. indicates that you failed to allocate memory for the string (re-
  57. member, you're only allocated space for an array of pointers,
  58. and not to what they point).
  59.  
  60. Bill McCarthy
  61. actuary@nando.net
  62. Wendell, NC  USA
  63.